﻿Imports FinanceiroBLL
Imports FinanceiroDAL.ModuloConexao
Public Class ContasReceberFRM
#Region "Radio Button"
    Private Sub RBAbertos_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBAbertos.CheckedChanged
        If RBAbertos.Checked Then
            gerarelatrio("Contas a Receber-Parcelas em aberto", "{vw_FinContasReceber.sta_codigo}=4")
        End If
    End Sub
    'recebidos
    Private Sub RBRecebidos_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBRecebidos.CheckedChanged
        If RBRecebidos.Checked Then
            gerarelatrio("Contas a Receber-Parcelas recebidas", "{vw_FinContasReceber.sta_codigo}=6")
        End If
    End Sub
    'recebidos do dia
    Private Sub RBRecebidosdia_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBRecebidosdia.CheckedChanged
        If RBRecebidosdia.Checked Then
            gerarelatrio("Contas a Receber-Recebimentos do Dia", "{vw_FinContasReceber.sta_codigo}=6 and {vw_FinContasReceber.icr_dtrecebimento}='" & Date.Now.ToString("yyyy-MM-dd") & "'")
        End If
    End Sub
    'atrasados
    Private Sub RbAtrasados_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RbAtrasados.CheckedChanged
        If RbAtrasados.Checked Then
            gerarelatrio("Contas a Receber-Parcelas atrasadas", "{vw_FinContasReceber.sta_codigo}=4 and {vw_FinContasReceber.icr_dtvencimento} < '" & Date.Now.ToString("yyyy-MM-dd") & "'")
        End If

        '(({vw_FinContasReceber.sta_codigo} = 6 ) and ({vw_FinContasReceber.icr_dtvencimento} < DateAdd('d',0,CurrentDate)))
    End Sub
    'recebidos por período
    Private Sub RBRecperiodo_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBRecperiodo.CheckedChanged
        If RBRecperiodo.Checked = True Then
            gbPeriodo.Enabled = True
        End If
    End Sub
    'geral
    Private Sub RBTodas_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBTodas.CheckedChanged
        If (RBTodas.Checked) Then
            gerarelatrio("Contas a Receber-Todas as parcelas", "")
        End If

    End Sub
    'por clientes
    Private Sub RBClientes_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBClientes.CheckedChanged
        If RBClientes.Checked = True Then
            gbCliente.Enabled = True
        End If
    End Sub
#End Region
#Region "Relatorio"
    Public Sub gerarelatrio(titulo As String, formula As String)
        Try
            Dim frmctasreceber As New RelatoriosfinFRM
            Dim rpt As New ContasReceberREL
            Try
                rpt.SetDatabaseLogon(usuario, senha)
                rpt.SetParameterValue(0, titulo)
                rpt.RecordSelectionFormula = formula
                frmctasreceber.CrystalReportViewer2.ShowGroupTreeButton = False
                frmctasreceber.CrystalReportViewer2.ReportSource = rpt
                frmctasreceber.ShowDialog()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            frmctasreceber.Dispose()
            rpt = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally

        End Try
    End Sub
#End Region
#Region "Load"
    Private Sub RelContasReceber_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        carregarb()
    End Sub
#End Region
#Region "Carrega"
    Sub carregarb()
        RBAbertos.Checked = False
        RbAtrasados.Checked = False
        RBClientes.Checked = False
        RBRecebidos.Checked = False
        RBRecebidosdia.Checked = False
        RBRecperiodo.Checked = False
        RBTodas.Checked = False
    End Sub
#End Region
#Region "BTok"
    Private Sub BTNok_Click(sender As System.Object, e As System.EventArgs) Handles BTNok.Click
        If RBRecperiodo.Checked = True Then
            Dim opt As Integer = 0
            opt = DateTime.Compare(dtinicio.Value, dtfim.Value)
            If opt <= 0 Then
                gerarelatrio("Parcelas recebidas entre:" & dtinicio.Value.Date & " até " & dtfim.Value.Date, "{vw_FinContasReceber.sta_codigo} =6 and {vw_FinContasReceber.ccc_codigo} > 0  and {vw_FinContasReceber.icr_dtrecebimento} >='" & dtinicio.Value.ToString("yyyy-MM-dd") & "' and {vw_FinContasReceber.icr_dtrecebimento} <= '" & dtfim.Value.ToString("yyyy-MM-dd") & "'")
            End If
        End If
    End Sub
#End Region
#Region "OK"
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles BOK.Click
        If RBClientes.Checked Then
            If txtNome.Text <> "" Then
                gerarelatrio("Parcelas por clientes", "{vw_FinContasReceber.sta_codigo}=4  And {vw_FinContasReceber.cli_nome} ='" & (txtNome.Text) & "'")
                txtNome.Text = ""
            End If
        End If
    End Sub
#End Region
#Region "Localiza"
    Private Sub BLocaliza_Click(sender As System.Object, e As System.EventArgs) Handles BLocaliza.Click
        Dim frmpes As New ClientesCON
        frmpes.tipo = "ret"
        frmpes.ShowDialog()
        txtNome.Text = frmpes.cliente
        frmpes.Dispose()
        frmpes = Nothing
        ' txtNome.Text = ""
    End Sub
#End Region
End Class